package ru.timofeyco.justfeelbetter.adapters;

import java.util.ArrayList;

import ru.timofeyco.justfeelbetter.R;
import ru.timofeyco.justfeelbetter.model.DrillType;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;

public class TrainingDrillTypesAdapter extends ArrayAdapter<DrillType> {
	private ArrayList<DrillType> items;
	private Context context;
	
	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public TrainingDrillTypesAdapter(Context context, int textViewResourceId,
			ArrayList<DrillType> objects) {
		super(context, textViewResourceId, objects);
		this.items = objects;			
		this.context = context;
	}
	
	 @Override
	 public View getView(int position, View convertView, ViewGroup parent) {
	     View view = convertView;
	     if (view == null) {
	         LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    	 view = layoutInflater.inflate(R.layout.training_drill_types_row, null);
	     }
	     DrillType drillType = items.get(position);
	     if (drillType != null) {
	         CheckBox drillCheckBox = (CheckBox) view.findViewById(R.id.trainingDrillTypeCheckBox);             
	         if (drillCheckBox != null) {            	 
	        	 drillCheckBox.setText(drillType.getName());  	        	
	         }             	         
	     }
	     return view;
	 }	

}
